const {
	$U_UserInfo,
	$U_LocalUserInfo,
} = require('@utils/storage')

module.exports = {

	loginMethod() {
		let {
			formComp,
			accountComp,
			passwordComp,
			store,
		} = this
		if (store.isLogin)
			return false
		formComp.form('submit', {
			url: '/ult/login',
			onSubmit(params) {
				let isValid = formComp.form('validate');
				if (!isValid) {
					$.messager.progress('close');
				}
				return isValid;
			},
			success(data) {
				if (typeof data != 'object') {
					try {
						data = JSON.parse(data)
					} catch (e) {}
				}
				if (!data || !data.id) {
					$.messager.alert({
						title: '提示',
						msg: data && data.error,
					})
					return false
				}
				data.orgPassword = passwordComp.passwordbox('getValue');
				// passwordComp.passwordbox('setValue', '')
				// accountComp.textbox('setValue', '')
				$.messager.progress('close');
				$U_UserInfo(data)
				store.isLogin = true
				setTimeout(function() {
					$.spaRouters.next('main')
				}, 200)
			}
		})
	}
}